#include <iostream>
using namespace std;
using ll=long long;
int main() {

	int n;
	ll nRet=-1e10,nSum=0;
	cin>>n;
	ll t;
	for(int i=0;i<n;++i){
		cin>>t;
		nSum+=t;
		nRet=max(nRet,nSum);
		if(nSum<0){
			nSum=0;
		}				
	}
	cout<<nRet<<endl;
	
	return 0;
}
